<div class="layui-card-header layui-card">
    <span class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">首页</a>
        <a><cite>申请结算</cite></a>
    </span>
</div>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <li class="layui-this">申请结算</li>
            </ul>
            <div class="layui-tab-content" style="width:50%;margin:0 auto">
                <form class="layui-form center">
                    <div class="layui-form-item">
                        <label class="layui-form-label">账号名称</label>
                        <div class="layui-input-block">
                            <input type="text"  required lay-verify="required" autocomplete="off" class="layui-input amountName" disabled style="border:none">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">账号类型</label>
                        <div class="layui-input-block">
                            <input type="text" id="selBankT" required name="accountType" lay-verify="required" autocomplete="off" class="layui-input" disabled style="border:none">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">账号信息</label>
                        <div class="layui-input-block">
                            <input type="text" required  lay-verify="required"  autocomplete="off" class="layui-input amountInfo" disabled style="border:none">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">备注</label>
                        <div class="layui-input-block">
                            <input type="text" required  lay-verify="required"  autocomplete="off" class="layui-input amountRemark" disabled style="border:none">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">结算金额(元)</label>
                        <div class="layui-input-block">
                            <input type="text" required  name="settAmount"  lay-verify="required|number" placeholder="请输入结算金额" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">支付密码</label>
                        <div class="layui-input-block">
                            <input type="password" required  name="payPassword"  lay-verify="required|pass" placeholder="请输入支付密码" autocomplete="off" class="layui-input pwd">
                        </div>
                    </div>
                    <div class="layui-form-item ">
                        <div class="layui-input-block">
                            <button type="button" lay-submit lay-filter="btnJSJ" class="layui-btn">提交申请</button>
                            <a href="" class="layui-btn">返回</a>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['form','util','admin'], function(){
       var form = layui.form
       ,$ = layui.$
       ,admin = layui.admin
       ,element = layui.element;


       element.render('breadcrumb', 'breadcrumb');//渲染导航信息
    
       var defaultBid = '';
       admin.req({
           type: 'get',
           url: layui.setter.baseUrl + '/bank_account/default_get',
           error: function(err){
               layer.alert(err.msg,{title:'请求失败'})
           },
           success:function(res){
                if(res.code == 0 && res.data != null){
                    $('.center').css('display','block');
                    $('.applyBtn').css('display','none');
                    $('.amountName').val(res.data.name);
                  var accType = res.data.accountType==1?"银行账号":res.data.accountType==2?"支付宝账号":res.data.accountType==3?"微信账号":"非法账号"
                    $('#selBankT').val(accType);
                    $('.amountInfo').val(res.data.mchId);
                    $('.amountRemark').val(res.data.remark)
                    defaultBid = res.data.id;

                }else if(res.code == 0 && res.data == null){
                    $('.center').css('display','none');
                    layer.alert('您还没有默认账号，请先到银行账号设置默认账号',function(){
                        location.hash =  "/sett/bank/";
                    });
                }else{
                    layer.alert(res.msg,{title: "查询失败"})
                }
           }
       })


       form.on('submit(btnJSJ)', function(data){
            // 在这个回调函数里面写ajax提交
            admin.req({
                type: 'post',
                url: layui.setter.baseUrl + '/sett/apply',
                // data: "params=" + JSON.stringify(data.field),
                data: {
                    accountType : data.field.accountType,
                    settAmount: data.field.settAmount,
                    bankAccountId:defaultBid,
                    payPassword:data.field.payPassword
                },
                success: function(res){
                    if(res.code == 0){
                        layer.alert(res.msg,{title: "保存成功"},function(index){
                            layer.close(index);
                            location.hash = '/sett/manage/list';
                        })
                    }else {
                        layer.alert(res.msg,{title: '保存失败'})
                    }

                }
            })
            return false;//阻止跳转
        });
        form.render();
       
    })
</script>